package com.flot.yazb.base.rxjava;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by fengdongfei on 2017/8/27.
 */

public class RxjavaAndRetrofit {

    public void dothat(){
        final RBService updateService =
                ServiceFactory.createServiceFrom(RBService.class, "");
        // 普通callback形式
        updateService.getCallUser("", new Callback<Student>() {
            @Override
            public void onResponse(Call<Student> call, Response<Student> response) {

            }

            @Override
            public void onFailure(Call<Student> call, Throwable t) {

            }
        });

        // rxjava实现callback--后台代码和前台代码全都写在一条链中，明显清晰了
        updateService.getUser("110")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Student>() {
                    @Override
                    public void onNext(Student user) {
//                        userView.setUser(user);
                    }

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable error) {
                        // Error handling
                    }
                });
    }


}
